package com.example.backend.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.backend.common.result.Result;
import com.example.backend.dto.BorrowDTO;
import com.example.backend.service.BorrowService;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/borrow")
public class BorrowController {
    
    private final BorrowService borrowService;
    
    public BorrowController(BorrowService borrowService) {
        this.borrowService = borrowService;
    }
    
    @GetMapping("/page")
    public Result<Page<BorrowDTO>> page(
            @RequestParam(defaultValue = "1") Integer current,
            @RequestParam(defaultValue = "10") Integer size,
            @RequestParam(required = false) Long userId) {
        Page<BorrowDTO> page = borrowService.page(current, size, userId);
        return Result.success(page);
    }
    
    @PostMapping("/{bookId}")
    public Result<Void> borrow(@PathVariable Long bookId) {
        borrowService.borrow(bookId);
        return Result.success();
    }
    
    @PostMapping("/approve/{id}")
    public Result<Void> approve(@PathVariable Long id) {
        borrowService.approve(id);
        return Result.success();
    }
    
    @PostMapping("/reject/{id}")
    public Result<Void> reject(@PathVariable Long id) {
        borrowService.reject(id);
        return Result.success();
    }
    
    @PostMapping("/return/{id}")
    public Result<Void> returnBook(@PathVariable Long id) {
        borrowService.returnBook(id);
        return Result.success();
    }
} 